import java.util.Queue;
public class GenericQueueOperations {
        public static <T> void processQueue(Queue<T> queue) {
            if (queue.isEmpty()) {
                System.out.println("Queue is empty.");
                return;
            }

            T firstElement = queue.peek();

            if (firstElement instanceof Integer) {
                int sum = 0;
                for (T element : queue) {
                    sum += (Integer) element;
                }
                System.out.println("Sum of integers in the queue: " + sum);
            } else if (firstElement instanceof String) {
                StringBuilder concatenatedString = new StringBuilder();
                for (T element : queue) {
                    concatenatedString.append((String) element);
                }
                System.out.println("Concatenated string: " + concatenatedString.toString());
            } else {
                System.out.println("Is not integer or string.");
            }
        }

        public static void main(String[] args) {
            // 创建整型队列并测试整数累加操作
            Queue<Integer> integerQueue = new java.util.LinkedList<>();
            integerQueue.offer(1);
            integerQueue.offer(2);
            integerQueue.offer(3);
            processQueue(integerQueue);

            // 创建字符型队列并测试字符连接操作
            Queue<String> stringQueue = new java.util.LinkedList<>();
            stringQueue.offer("Hello ");
            stringQueue.offer("world");
            stringQueue.offer("!");
            processQueue(stringQueue);

            // 创建其他类型队列并测试
            Queue<Double> doubleQueue = new java.util.LinkedList<>();
            doubleQueue.offer(3.14);
            doubleQueue.offer(2.718);
            processQueue(doubleQueue);
        }
}
